//
//  TweetCell.m
//  Coding_My
//
//  Created by showXxie on 2017/8/21.
//  Copyright © 2017年 sooxie. All rights reserved.
//

#import "TweetCell.h"
#import "UITapImageView.h"
#import "UITTTAttributedLabel.h"
#import "UICustomCollectionView.h"
#import "TweetMediaItemCCell.h"
#import "TweetMediaItemSingleCCell.h"

#define kTweetCell_PadingLeft kPaddingLeftWidth
#define kTweetCell_PadingTop (65 + 15)

#define kTweetCell_PadingBottom 10.0
#define kTweetCell_ContentWidth (kScreen_Width -kTweetCell_PadingLeft - kPaddingLeftWidth)
#define kTweetCell_LikeComment_Height 27.0
#define kTweetCell_LikeComment_Width 50.0
#define kTweetCell_LikeUserCCell_Height 26.0
#define kTweetCell_LikeUserCCell_Pading 10.0
#define kTweet_ContentFont [UIFont systemFontOfSize:16]
#define kTweet_ContentMaxHeight 200.0
#define kTweet_CommentFont [UIFont systemFontOfSize:14]
#define kTweet_TimtFont [UIFont systemFontOfSize:12]
#define kTweet_LikeUsersLineCount 7.0

#define kTweetCell_MaxCollectionNum (kDevice_Is_iPhone6Plus? 12: kDevice_Is_iPhone6? 10 : 9)

@interface TweetCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UIView *topView;

@property (strong, nonatomic) UITapImageView *ownerImgView;
@property (strong, nonatomic) UIButton *ownerNameBtn;
@property (strong, nonatomic) UILabel *timeLabel, *fromLabel;
@property (assign, nonatomic) BOOL needTopView;

@property (strong, nonatomic) UITTTAttributedLabel *contentLabel;
@property (strong, nonatomic) UIButton *likeBtn, *commentBtn, *deleteBtn, *rewardBtn;
@property (strong, nonatomic) UIButton *locaitonBtn;
@property (strong, nonatomic) UIImageView *timeClockIconView, *commentOrLikeBeginImgView, *commentOrLikeSplitlineView, *fromPhoneIconView;
@property (strong, nonatomic) UICollectionView *likeUsersView;
@property (strong, nonatomic) UITableView *commentListView;
@property (strong, nonatomic) UICustomCollectionView *mediaView;

@end

@implementation TweetCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setUI];

        
    }
    return self;
}


#pragma mark - 布局ui
- (void)setUI {
    
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 15)];
        _topView.backgroundColor = kColorTableSectionBg;
        
        [self.contentView addSubview:_topView];
    }
    
    if (!self.ownerImgView) {
        self.ownerImgView = [[UITapImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 15 + CGRectGetMaxY(_topView.frame), 38, 38)];
        [self.ownerImgView doCircleFrame];
        [self.contentView addSubview:self.ownerImgView];
        
      
    }
    
    //名字
    
    if (!self.ownerNameBtn) {
        self.ownerNameBtn = [UIButton buttonWithUserStyle];
        self.ownerNameBtn.frame = CGRectMake(CGRectGetMaxX(self.ownerImgView.frame) + 10, 23 + CGRectGetMaxY(_topView.frame), 50, 20);
        [self.ownerNameBtn addTarget:self action:@selector(userBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.ownerNameBtn];
        [_ownerNameBtn setTitle:@"sooxie" forState:UIControlStateNormal];
    }
    
    if (!self.timeLabel) {
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.ownerNameBtn.frame), 0, kScreen_Width/2, 12)];
        //            self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width - kPaddingLeftWidth - 55, 23 + CGRectGetMaxY(_topView.frame), 55, 12)];
        self.timeLabel.font = kTweet_TimtFont;
        //            self.timeLabel.textAlignment = NSTextAlignmentRight;
        self.timeLabel.textColor = kColor999;
        [self.contentView addSubview:self.timeLabel];
        
         _timeLabel.text = @"45分钟前";
    }
    
    
    if (!self.contentLabel) {
        self.contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kTweetCell_PadingLeft, kTweetCell_PadingTop, kTweetCell_ContentWidth, 20)];
        self.contentLabel.font = kTweet_ContentFont;
        self.contentLabel.textColor = kColor222;
        self.contentLabel.numberOfLines = 0;
        
        self.contentLabel.linkAttributes = kLinkAttributes;
        self.contentLabel.activeLinkAttributes = kLinkAttributesActive;
        self.contentLabel.delegate = self;
        [self.contentLabel addLongPressForCopy];
        [self.contentView addSubview:self.contentLabel];
        
    }
    
    //喜欢
    if (!self.likeBtn) {
        CGRect frame = CGRectMake(kPaddingLeftWidth, 0, kTweetCell_LikeComment_Width, kTweetCell_LikeComment_Height);
        self.likeBtn = [UIButton tweetBtnWithFrame:frame alignmentLeft:YES];
        [self.likeBtn addTarget:self action:@selector(likeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.likeBtn];
    }
    //打赏
    if (!self.rewardBtn) {
        CGRect frame = CGRectMake(kPaddingLeftWidth + kTweetCell_LikeComment_Width + 5, 0, kTweetCell_LikeComment_Width, kTweetCell_LikeComment_Height);
        self.rewardBtn = [UIButton tweetBtnWithFrame:frame alignmentLeft:YES];
        [self.rewardBtn addTarget:self action:@selector(rewardBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.rewardBtn];
    }
    
    //评论
    if (!self.commentBtn) {
        CGRect frame = CGRectMake(kScreen_Width - kPaddingLeftWidth- kTweetCell_LikeComment_Width, 0, kTweetCell_LikeComment_Width, kTweetCell_LikeComment_Height);
        self.commentBtn = [UIButton tweetBtnWithFrame:frame alignmentLeft:NO];
        [self.commentBtn setImage:[UIImage imageNamed:@"tweet_btn_comment"] forState:UIControlStateNormal];
        [self.commentBtn addTarget:self action:@selector(commentBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.commentBtn];
    }

    
    if (!self.deleteBtn) {
        self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.deleteBtn.frame = CGRectMake(kScreen_Width - kPaddingLeftWidth- 2*kTweetCell_LikeComment_Width -5, 0, kTweetCell_LikeComment_Width, kTweetCell_LikeComment_Height);
        [self.deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [self.deleteBtn setTitleColor:kColorBrandGreen forState:UIControlStateNormal];
        [self.deleteBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
        self.deleteBtn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
        [self.deleteBtn addTarget:self action:@selector(deleteBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:self.deleteBtn];
    }


    if (!self.locaitonBtn) {
        self.locaitonBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.locaitonBtn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        self.locaitonBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        self.locaitonBtn.frame = CGRectMake(kTweetCell_PadingLeft, 0, kScreen_Width - kTweetCell_PadingLeft - kPaddingLeftWidth, 15);
        self.locaitonBtn.titleLabel.adjustsFontSizeToFitWidth = NO;
        self.locaitonBtn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
        [self.locaitonBtn setTitleColor:kColorBrandGreen forState:UIControlStateNormal];
        [self.locaitonBtn addTarget:self action:@selector(locationBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.locaitonBtn];
    }
    
    //手机图标
    if (!self.fromPhoneIconView) {
        self.fromPhoneIconView = [[UIImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 0, 11, 11)];
        self.fromPhoneIconView.image = [UIImage imageNamed:@"little_phone_icon"];
        [self.contentView addSubview:self.fromPhoneIconView];
    }
    
    if (!self.fromLabel) {
        self.fromLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.fromPhoneIconView.frame) + 5, 0, kScreen_Width/2, 15)];
        self.fromLabel.font = kTweet_TimtFont;
        self.fromLabel.textColor = kColor999;
        [self.contentView addSubview:self.fromLabel];
        
        _fromLabel.text = @"fromLabel";
    }
    
    
    
    //剪头
    if (!_commentOrLikeBeginImgView) {
        _commentOrLikeBeginImgView = [[UIImageView alloc] initWithFrame:CGRectMake(kTweetCell_PadingLeft + 35, 0, 15, 7)];
        _commentOrLikeBeginImgView.image = [UIImage imageNamed:@"commentOrLikeBeginImg"];
        [self.contentView addSubview:_commentOrLikeBeginImgView];
    }
    
    //喜欢头像 collectionView
    if (!self.likeUsersView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        self.likeUsersView = [[UICollectionView alloc] initWithFrame:CGRectMake(kTweetCell_PadingLeft, 0, kTweetCell_ContentWidth, 35) collectionViewLayout:layout];
        self.likeUsersView.scrollEnabled = NO;
        [self.likeUsersView setBackgroundView:nil];
        [self.likeUsersView setBackgroundColor:kColorTableSectionBg];
        [self.likeUsersView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
        self.likeUsersView.dataSource = self;
        self.likeUsersView.delegate = self;
        [self.contentView addSubview:self.likeUsersView];
    }
    
    //分割线
    if (!_commentOrLikeSplitlineView) {
        _commentOrLikeSplitlineView = [[UIImageView alloc] initWithFrame:CGRectMake(kTweetCell_PadingLeft, 0, kTweetCell_ContentWidth, 1)];
        _commentOrLikeSplitlineView.image = [UIImage imageNamed:@"splitlineImg"];
        [self.contentView addSubview:_commentOrLikeSplitlineView];
    }

    
    
    //评论列表
    if (!self.commentListView) {
        self.commentListView = [[UITableView alloc] initWithFrame:CGRectMake(kTweetCell_PadingLeft, 0, kTweetCell_ContentWidth, 20) style:UITableViewStylePlain];
        self.commentListView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.commentListView.scrollEnabled = NO;
        [self.commentListView setBackgroundView:nil];
        [self.commentListView setBackgroundColor:kColorTableSectionBg];
        [self.commentListView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
//        [self.commentListView registerClass:[TweetCommentMoreCell class] forCellReuseIdentifier:kCellIdentifier_TweetCommentMore];
        self.commentListView.dataSource = self;
        self.commentListView.delegate = self;
        [self.contentView addSubview:self.commentListView];
    }

    
    //图片列表
    if (!self.mediaView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        //宽度为屏幕宽-30
        self.mediaView = [[UICustomCollectionView alloc] initWithFrame:CGRectMake(kTweetCell_PadingLeft, 0, kTweetCell_ContentWidth, 80) collectionViewLayout:layout];
        self.mediaView.scrollEnabled = NO;
        [self.mediaView setBackgroundView:nil];
        [self.mediaView setBackgroundColor:[UIColor clearColor]];
        [self.mediaView registerClass:[TweetMediaItemCCell class] forCellWithReuseIdentifier:kCCellIdentifier_TweetMediaItem];
        [self.mediaView registerClass:[TweetMediaItemSingleCCell class] forCellWithReuseIdentifier:kCCellIdentifier_TweetMediaItemSingle];
        self.mediaView.dataSource = self;
        self.mediaView.delegate = self;
        [self.contentView addSubview:self.mediaView];
    }

    
    

    
}


#pragma mark - 设置数据
- (void)setTweet:(Tweet *)tweet needTopView:(BOOL)needTopView{
    _tweet = tweet;
    _needTopView = needTopView;
   
    if (!_tweet) {
        return;
    }

    self.topView.hidden = !_needTopView;
    
    //owner头像
    __weak __typeof(self)weakSelf = self;
    //获得适合屏幕缩放比的图片
    [self.ownerImgView setImageWithUrl:[NSURL URLWithString:@"http://upload.jianshu.io/users/upload_avatars/304825/36f53ed6a58d.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240"] placeholderImage:kPlaceholderMonkeyRoundView(_ownerImgView) tapBlock:^(id obj) {
    }];
    
    
    //owner姓名
    [self.ownerNameBtn setUserTitle:@"sooxie" font:[UIFont systemFontOfSize:17] maxWidth:(kTweetCell_ContentWidth-85)];
    //发出冒泡的时间
   self.timeLabel.text = @"1小时前";

    CGFloat centerY = 15 + 15 + CGRectGetHeight(_ownerImgView.frame)/2;
    CGFloat curBottomY = _needTopView? 0: -15;
    centerY += curBottomY;
    
    [self.topView setY:curBottomY];
    [self.ownerImgView setCenterY:centerY];
    [self.ownerNameBtn setY:CGRectGetMinY(self.ownerImgView.frame)];
    [self.timeLabel setY:CGRectGetMaxY(self.ownerImgView.frame) - CGRectGetHeight(self.timeLabel.frame)];

    curBottomY += kTweetCell_PadingTop;
    //owner冒泡text内容
    [self.contentLabel setY:curBottomY];
    
    
    [self.contentLabel setLongString:_tweet.content  withFitWidth:kTweetCell_ContentWidth maxHeight:kTweet_ContentMaxHeight];
    
    curBottomY += [TweetCell contentLabelHeightWithTweet:_tweet];
    
    
    //图片缩略图展示
    if (_tweet.likes.integerValue > 0) {
    
        CGFloat mediaHeight = [TweetCell contentMediaHeightWithTweet:_tweet];
       
        CGFloat mediaWidth = kTweetCell_ContentWidth;
        [self.mediaView setFrame:CGRectMake(kTweetCell_PadingLeft, curBottomY, mediaWidth, mediaHeight)];
        [self.mediaView reloadData];
        self.mediaView.hidden = NO;
        curBottomY += mediaHeight;
    }else{
        if (self.mediaView) {
            self.mediaView.hidden = YES;
        }
    }
    
    //地址&设备小尾巴设置 frame
    if (_tweet.location.length > 0 || _tweet.device.length > 0) {
        if (_tweet.location.length > 0) {
            [self.locaitonBtn setTitle:_tweet.location forState:UIControlStateNormal];
            [self.locaitonBtn setY:curBottomY];
            curBottomY += _tweet.device.length > 0? 20: 15;
        }
        
        if (_tweet.device.length > 0) {
            self.fromLabel.text = [NSString stringWithFormat:@"来自 %@", _tweet.device];
            [self.fromLabel setY:curBottomY];
            [self.fromPhoneIconView setCenterY:self.fromLabel.centerY];
            curBottomY += 15;
        }
        curBottomY += 15;
    }
    //地址&设备x隐藏设置
    self.locaitonBtn.hidden = _tweet.location.length <= 0;
    self.fromLabel.hidden = self.fromPhoneIconView.hidden = _tweet.device.length <= 0;
    
    //喜欢&评论 按钮
    curBottomY += 5;
    curBottomY += 5;
    
    self.likeBtn.y = self.rewardBtn.y = self.commentBtn.y = curBottomY;
    
    //喜欢按钮
    [self.likeBtn setImage:[UIImage imageNamed:(_tweet.liked.boolValue? @"tweet_btn_liked":@"tweet_btn_like")] forState:UIControlStateNormal];
    [self.likeBtn setTitle:_tweet.likes.stringValue forState:UIControlStateNormal];
    
    [self.rewardBtn setImage:[UIImage imageNamed:(_tweet.rewarded.boolValue? @"tweet_btn_rewarded": @"tweet_btn_reward")] forState:UIControlStateNormal];
    
    [self.rewardBtn setTitle:_tweet.rewards.stringValue forState:UIControlStateNormal];
    [self.commentBtn setTitle:_tweet.comments.stringValue forState:UIControlStateNormal];
    
    [self.commentBtn setTitle:_tweet.comments.stringValue forState:UIControlStateNormal];

    [self.deleteBtn setY:curBottomY];

    self.deleteBtn.hidden = NO;
   
    curBottomY += kTweetCell_LikeComment_Height;
    
    //设置喜欢头像的y
    curBottomY += [TweetCell likeCommentBtn_BottomPadingWithTweet:_tweet];

    
    if ([_tweet hasLikesOrRewards]) {
        [_commentOrLikeBeginImgView setY:(curBottomY - CGRectGetHeight(_commentOrLikeBeginImgView.frame) + 1)];
        _commentOrLikeBeginImgView.hidden = NO;
    }else{
        _commentOrLikeBeginImgView.hidden = YES;
    }
    
    
    //点赞的人_列表
    //    可有可无
    if ([_tweet hasLikesOrRewards]) {
        CGFloat likeUsersHeight = [TweetCell likeUsersHeightWithTweet:_tweet];
        [self.likeUsersView setFrame:CGRectMake(kTweetCell_PadingLeft, curBottomY, kTweetCell_ContentWidth, likeUsersHeight)];
        [self.likeUsersView reloadData];
        self.likeUsersView.hidden = NO;
        curBottomY += likeUsersHeight;
    }else{
        if (self.likeUsersView) {
            self.likeUsersView.hidden = YES;
        }
    }
    
    
    //评论与赞的分割线
    if ([_tweet hasLikesOrRewards]) {
        [_commentOrLikeSplitlineView setY:(curBottomY -1)];
        _commentOrLikeSplitlineView.hidden = NO;
    }else{
        _commentOrLikeSplitlineView.hidden = YES;
    }
    
    
    
    //评论的人_列表
    //    可有可无
    if (/* DISABLES CODE */ (YES)) {
        CGFloat commentListViewHeight = [TweetCell commentListViewHeightWithTweet:_tweet];
        [self.commentListView setFrame:CGRectMake(kTweetCell_PadingLeft, floor(2*curBottomY)/2.0, kTweetCell_ContentWidth, commentListViewHeight)];
        [self.commentListView reloadData];
        self.commentListView.hidden = NO;
    }else{
        if (self.commentListView) {
            self.commentListView.hidden = YES;
        }
    }




}

+ (CGFloat)likeUsersHeightWithTweet:(Tweet *)tweet{
    CGFloat likeUsersHeight = 0;
    if ([tweet hasLikesOrRewards]) {
        likeUsersHeight = 45;
        //        +30*(ceilf([tweet.like_users count]/kTweet_LikeUsersLineCount)-1);
    }
    return likeUsersHeight;
}

+ (CGFloat)contentLabelHeightWithTweet:(Tweet *)tweet{
    CGFloat height = 0;
    height += MIN(kTweet_ContentMaxHeight, [tweet.content getHeightWithFont:kTweet_ContentFont constrainedToSize:CGSizeMake(kTweetCell_ContentWidth, CGFLOAT_MAX)]);
        height += 15;
    
    return height;
}


#pragma mark - cell的高度
+ (CGFloat)cellHeightWithObj:(id)obj needTopView:(BOOL)needTopView {
    
    Tweet *tweet = (Tweet *)obj;

    CGFloat cellHeight = 0;
    cellHeight += needTopView? 0: -15;
    cellHeight +=  kTweetCell_PadingTop;
    cellHeight += [self contentLabelHeightWithTweet:tweet];
    //计算图片列表高度
    cellHeight += [self contentMediaHeightWithTweet:tweet];

    cellHeight += [self locationAndDeviceHeightWithTweet:tweet];

    cellHeight += 5+ kTweetCell_LikeComment_Height;

    //是否有人喜欢
    cellHeight += [TweetCell likeCommentBtn_BottomPadingWithTweet:tweet];

    cellHeight += [TweetCell likeUsersHeightWithTweet:tweet];

    //评论列表
    cellHeight += [TweetCell commentListViewHeightWithTweet:tweet];

    
    
    cellHeight += 15;
    return ceilf(cellHeight);
    
}

//图片列表高度
+ (CGFloat)contentMediaHeightWithTweet:(Tweet *)tweet{

    CGFloat contentMediaHeight = 0;
    
    contentMediaHeight += kTweetMediaItemCCell_Width;
    
    contentMediaHeight += 15;//padding


    return contentMediaHeight;
}


//评论列表高度
+ (CGFloat)commentListViewHeightWithTweet:(Tweet *)tweet{

    if (!tweet) {
        return 0;
    }
    CGFloat commentListViewHeight = 0;
    
    return 44*5;
    
}

+ (CGFloat)likeCommentBtn_BottomPadingWithTweet:(Tweet *)tweet{
    if (tweet &&
        ([tweet hasLikesOrRewards]
         ||tweet.comments.intValue> 0)){
            return 15.0;
        }else{
            return 0;
        }
}


//计算location和手机图标高度
+ (CGFloat)locationAndDeviceHeightWithTweet:(Tweet *)tweet{
    CGFloat height = 0;
    if (tweet.location.length > 0 || tweet.device.length > 0) {
        if (tweet.location.length > 0) {
            height += tweet.device.length > 0? 20: 15;
        }
        if (tweet.device.length > 0) {
            height += 15;
        }
        height += 15;
    }
    return height;
}

//MARK: -- 喜欢点击
- (void)likeBtnClicked:(id)sender{
    
    BOOL preLiked = _tweet.liked.boolValue;

    //重新加载likes
   [_tweet changeToLiked:[NSNumber numberWithBool:!preLiked]];
    
    if (_cellRefreshBlock) {
        _cellRefreshBlock();
    }
    
    //开始动画
    if (preLiked) {//不喜欢
        [self.likeBtn setImage:[UIImage imageNamed:@"tweet_btn_like"] forState:UIControlStateNormal];
    }else{//喜欢
        [self.likeBtn animateToImage:@"tweet_btn_liked"];
    }


    
}



#pragma mark Collection 喜欢人头像列表  & 图片列表
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    //图片视图
    NSInteger row = 0;

    if (collectionView == _mediaView) {
        return 3;
    }else {
        return 10;

    }
  
    
    return row;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (collectionView == _mediaView) {
        
        
        TweetMediaItemCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier:kCCellIdentifier_TweetMediaItem forIndexPath:indexPath];
        return ccell;
        
//        if (/* DISABLES CODE */ (YES)) {//单张图片
//           
//            TweetMediaItemSingleCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier:kCCellIdentifier_TweetMediaItemSingle forIndexPath:indexPath];
//            return ccell;
//
//        }else {//多张图片
//            
//            TweetMediaItemCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier:kCCellIdentifier_TweetMediaItem forIndexPath:indexPath];
//            return ccell;
//            
//        }
    }
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor orangeColor];
    return cell;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (collectionView == _mediaView) {
     CGSize itemSize = CGSizeMake(kTweetMediaItemCCell_Width, kTweetMediaItemCCell_Width);

        return itemSize;
        
    }

    CGSize itemSize = CGSizeMake(26, 26);

    return itemSize;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    if (collectionView == _mediaView) {
        UIEdgeInsets  insetForSection = UIEdgeInsetsMake(0, 0, 0, 0);
        
        return insetForSection;
    }
    UIEdgeInsets insetForSection = UIEdgeInsetsMake(kTweetCell_LikeUserCCell_Pading, 5, kTweetCell_LikeUserCCell_Pading, 5);
    
    return insetForSection;

}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    if (collectionView == _mediaView) {
     
        return 3.0;

    
    }
  
    return kTweetCell_LikeUserCCell_Pading;
   
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    if (collectionView == _mediaView) {
        return 2.0;

    }
   
    return kTweetCell_LikeUserCCell_Pading/2;
    
}


#pragma mark - tableView 评论列表
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = @"厉害了 我的波！";
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 44;
    
}




@end
